import miniApp, {
    analyticsBase,
    authorizeParams,
    gameRecorderStartParams,
    getUserInfoParams,
    loadParams,
    loginParams, ModalParams, SHARE_VIDEO_SORT_TYPE, ShareVideoRankDetail,
    toastParams,
    UserInfo
} from "../miniApp";
import {dataField} from "../dataField";

export default class H5Api extends miniApp {
    async commitRank(rankId: dataField.RANK_ID, score: number): Promise<boolean> {
        return Promise.resolve(false);
        // throw new Error("Method not implemented.");
    }

    async showRank(rankId: dataField.RANK_ID): Promise<boolean> {
        return Promise.resolve(false);
        // throw new Error("Method not implemented.");
    }

    LocalInBlockCityList(): boolean {
        return false;
    }

    vibrate(type): void {
        console.log('h5 振动');
    }

    protected m_appId: string = '';
    protected m_secret: string = '';
    protected m_adUnitId: string = '';

    static getRandNameAndUrl(): UserInfo {
        let user: UserInfo = {
            nickName: `零一侠`,//侠客${data_control.getRandId(6)}
            avatarUrl: null,
            language: 'ch',
            gender: 0,
            country: '中国',        //用户所在国家
            province: '',        //用户所在省份
            city: '',            //用户所在城市
        };

        return user;
    };

    validAppId(): void {
    }

    getUserInfo(params: getUserInfoParams): void {
        params.success && params.success({userInfo: H5Api.getRandNameAndUrl()});
    }

    showToast(params: toastParams): void {
        // O1HD.getManagers().uiMgr.showMessageBox(params.title);
    }

    showLoading(params: loadParams): void {
        console.log('h5 显示进度', params);
    }

    hideLoading(): void {
        console.log('h5 隐藏进度');
    }

    preCreateUnits(): void {
        // console.log(DEEP_NEXT_SPLIT, 'h5 预先创建');
    }

    loadAndShowVideoAd(successCallback: () => void, errorCallback: (error: any) => void, completeCallback?: () => void,title?:string): void {
        console.log(`H5 广告加载并显示,发送埋点${title}`);
        successCallback && successCallback();
        completeCallback && completeCallback();
    }

    authorize(params: authorizeParams): void {
        params.success && params.success();
    }

    login(params: loginParams): void {
        params.success && params.success({code: null});
    }

    gameRecordStart(params: gameRecorderStartParams, onStart?: (res) => void): void {
        console.log('h5 录屏start');
        onStart && onStart(null);
    }

    gameRecordStop(): boolean {
        console.log('h5 录屏stop');
        return true;
    }

    shareGameRecordVideo(successCb?: () => void, failCb?: () => void): void {
        console.log('h5 分享录屏');
        successCb && successCb();
    }

    isProduction(): boolean {
        return H5Api.isProduction();
    }


    isHaveShareVideo(): boolean {
        return true;
    }

    reportAnalytics(EventKey: string, data: any): void {
        console.log('h5 发送埋点');
        return;
    }

    clearMemory(): void {

    }

    shareAppMessage(args: any): void {
    }

    operateGameLive(): void {
    }

    static isProduction(): boolean {
        return true;
    }

    createMoreGameBtn(): void {
    }

    hideBanner(): void {
    }

    showBannerAD(node: cc.Node, successCallback?: () => void, errorCallback?: (error: any) => void): void {
    }

    showInterstitialAd(onAdClose: () => void, onFailed: () => void): void {
    }

    showNativeAd(): void {
    }

    reportAdClickNativeAd(): void {

    }

    addShortcut(): Promise<boolean> {
        console.log('h5 添加桌面');
        //
        return Promise.resolve(true);
    }

    drawUrlImage(url: string, overCb: (spf: cc.SpriteFrame) => void): void {
        cc.assetManager.loadRemote(url, (err, asset: cc.Texture2D) => {
            if (err) {
                console.error('#1553937 图片出错', err);
                overCb(null);
                return;
            }
            overCb(new cc.SpriteFrame(asset));
        });
    }

    showVideo(videoUrl: string): void {
    }

    getShareVideoRank(sortType: SHARE_VIDEO_SORT_TYPE, successCb: (data: ShareVideoRankDetail[]) => void): void {
        successCb([
            <ShareVideoRankDetail>{
                cover_url: "https://p6.toutiaoimg.com/img/tos-cn-i-0022/21042eee9d1a44cda8835b0586cf1d90~noop.jpeg?from=shortvideo",
                create_time: "2021-04-07 21:15:12",
                digg_count: "0",
                rank: 7,
                source: 13,
                user_name: "Visitor",
                video_id: "131047150d294037025515410e7d436501502b42017e4c605757404d01734560505247440973",
                video_tag: ""
            },
            <ShareVideoRankDetail>{
                cover_url: "https://p6.toutiaoimg.com/img/tos-cn-i-0022/21042eee9d1a44cda8835b0586cf1d90~noop.jpeg?from=shortvideo",
                create_time: "2021-04-07 21:15:12",
                digg_count: "0",
                rank: 7,
                source: 13,
                user_name: "Visitor",
                video_id: "131047150d294037025515410e7d436501502b42017e4c605757404d01734560505247440973",
                video_tag: ""
            },
            <ShareVideoRankDetail>{
                cover_url: "https://p6.toutiaoimg.com/img/tos-cn-i-0022/21042eee9d1a44cda8835b0586cf1d90~noop.jpeg?from=shortvideo",
                create_time: "2021-04-07 21:15:12",
                digg_count: "0",
                rank: 7,
                source: 13,
                user_name: "Visitor",
                video_id: "131047150d294037025515410e7d436501502b42017e4c605757404d01734560505247440973",
                video_tag: ""
            },
            <ShareVideoRankDetail>{
                cover_url: "https://p6.toutiaoimg.com/img/tos-cn-i-0022/21042eee9d1a44cda8835b0586cf1d90~noop.jpeg?from=shortvideo",
                create_time: "2021-04-07 21:15:12",
                digg_count: "0",
                rank: 7,
                source: 13,
                user_name: "Visitor",
                video_id: "131047150d294037025515410e7d436501502b42017e4c605757404d01734560505247440973",
                video_tag: ""
            },
            <ShareVideoRankDetail>{
                cover_url: "https://p6.toutiaoimg.com/img/tos-cn-i-0022/21042eee9d1a44cda8835b0586cf1d90~noop.jpeg?from=shortvideo",
                create_time: "2021-04-07 21:15:12",
                digg_count: "0",
                rank: 7,
                source: 13,
                user_name: "Visitor",
                video_id: "131047150d294037025515410e7d436501502b42017e4c605757404d01734560505247440973",
                video_tag: ""
            },
            <ShareVideoRankDetail>{
                cover_url: "https://p6.toutiaoimg.com/img/tos-cn-i-0022/21042eee9d1a44cda8835b0586cf1d90~noop.jpeg?from=shortvideo",
                create_time: "2021-04-07 21:15:12",
                digg_count: "0",
                rank: 7,
                source: 13,
                user_name: "Visitor",
                video_id: "131047150d294037025515410e7d436501502b42017e4c605757404d01734560505247440973",
                video_tag: ""
            },
            <ShareVideoRankDetail>{
                cover_url: "https://p6.toutiaoimg.com/img/tos-cn-i-0022/21042eee9d1a44cda8835b0586cf1d90~noop.jpeg?from=shortvideo",
                create_time: "2021-04-07 21:15:12",
                digg_count: "0",
                rank: 7,
                source: 13,
                user_name: "Visitor",
                video_id: "131047150d294037025515410e7d436501502b42017e4c605757404d01734560505247440973",
                video_tag: ""
            },
            <ShareVideoRankDetail>{
                cover_url: "https://p6.toutiaoimg.com/img/tos-cn-i-0022/21042eee9d1a44cda8835b0586cf1d90~noop.jpeg?from=shortvideo",
                create_time: "2021-04-07 21:15:12",
                digg_count: "0",
                rank: 7,
                source: 13,
                user_name: "Visitor",
                video_id: "131047150d294037025515410e7d436501502b42017e4c605757404d01734560505247440973",
                video_tag: ""
            },
            <ShareVideoRankDetail>{
                cover_url: "https://p6.toutiaoimg.com/img/tos-cn-i-0022/21042eee9d1a44cda8835b0586cf1d90~noop.jpeg?from=shortvideo",
                create_time: "2021-04-07 21:15:12",
                digg_count: "0",
                rank: 7,
                source: 13,
                user_name: "Visitor",
                video_id: "131047150d294037025515410e7d436501502b42017e4c605757404d01734560505247440973",
                video_tag: ""
            },
            <ShareVideoRankDetail>{
                cover_url: "https://p6.toutiaoimg.com/img/tos-cn-i-0022/21042eee9d1a44cda8835b0586cf1d90~noop.jpeg?from=shortvideo",
                create_time: "2021-04-07 21:15:12",
                digg_count: "0",
                rank: 7,
                source: 13,
                user_name: "Visitor",
                video_id: "131047150d294037025515410e7d436501502b42017e4c605757404d01734560505247440973",
                video_tag: ""
            },
        ]);
    }

    subscribeMessage(): void {
    }

    showAddFavoriteGuide(successCallback?: () => void, failCallback?: () => void, completeCallback?: () => void): void {
    }

    PlayLastRecordSound(scale?: number, successCb?: () => void, errorCb?: () => void): void {
        setTimeout(() => {
            successCb && successCb();
        }, 1000)
    }

    StartRecordSound(): void {
    }

    StopRecordSound(successCallback?: () => void): void {
        setTimeout(() => {
            successCallback && successCallback();
        }, 1000);
    }

    showModal(params: ModalParams): void {
        console.log('h5 对话框', params);
    }

    navigateToMiniGame(appId: string, successCallback?: () => void, failCallback?: () => void): void {
        console.log('h5 跳转到其他小游戏', appId);
        successCallback && successCallback();
    }

    WidgetfullScreen() {
        console.log("H5适配")
        cc.director.getScene().getChildByName("Canvas").getComponent(cc.Canvas).fitHeight  = true
    }
}


















